local sk__huchi = fk.CreateSkill {

  name = "sk__huchi",

  tags = {  },

}



sk__huchi:addEffect("viewas", {
  name = "sk__huchi",
  anim_type = "offensive",
  prompt = "#sk__huchi",
  card_filter = Util.FalseFunc,
  view_as = function(self, player,cards)
    local card = Fk:cloneCard("duel")
    card.skillName = sk__huchi.name
    return card
  end,
  before_use = function(self, player, use)
    use.prohibitedCardNames = {"nullification"}
  end,
  after_use = function(self, player, use)
    local room = player.room
    if not player.dead then
      if use.damageDealt then
        if use.extra_data and use.extra_data.sk__huchi then
          room:setPlayerMark(player, "@@sk__huchi-phase", 1)
        end
        if use.damageDealt[player] then
          player:drawCards(3, sk__huchi.name)
        end
      else
        room:setPlayerMark(player, "@@sk__huchi-phase", 1)
      end
    end
    for _, id in ipairs(use.tos) do
      local to = id
      if use.damageDealt and use.damageDealt[id] and not to.dead then
        to:drawCards(3, sk__huchi.name)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@@sk__huchi-phase") == 0
  end,
})

sk__huchi:addEffect(fk.EnterDying, {
  refresh_events = {fk.EnterDying},
  can_refresh = function(self, event, target, player, data)
    return data.damage and data.damage.card and table.contains(data.damage.card.skillNames, "sk__huchi")
  end,
  on_refresh = function(self, event, target, player, data)
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data
      use.extra_data = use.extra_data or {}
      use.extra_data.sk__huchi = true
    end
  end,
})

return sk__huchi